#include "html.h"

void not_found(int client_sock)//404
{
	const char* reply = "HTTP/1.0 404 NOT FOUND\r\n\
Content-Type: text/html\r\n\
\r\n\
<HTML lang=\"zh-CN\">\r\n\
<meta content=\"text/html; charset=utf-8\" http-equiv=\"Content-Type\">\r\n\
<HEAD>\r\n\
<TITLE>NOT FOUND</TITLE>\r\n\
</HEAD>\r\n\
<BODY>\r\n\
	<P>文件不存在！\r\n\
    <P>The server could not fulfill your request because the resource specified is unavailable or nonexistent.\r\n\
</BODY>\r\n\
</HTML>";
	int len = write(client_sock, reply, strlen(reply));
	if (debug)	fprintf(stdout, reply);
	if (len <= 0)
	{
		fprintf(stderr, "send reply failed reason: %s\n", strerror(errno));
	}
}

void unimplemented(int client_sock)//501
{
	const char* reply = "HTTP/1.0 501 Method Not Implemented\r\n\
Content-Type: text/html\r\n\
\r\n\
<HTML lang=\"zh-CN\">\r\n\
<meta content=\"text/html; charset=utf-8\" http-equiv=\"Content-Type\">\r\n\
<HEAD>\r\n\
<TITLE>Method Not Implemented</TITLE>\r\n\
</HEAD>\r\n\
<BODY>\r\n\
    <P>HTTP request method not supported.\r\n\
</BODY>\r\n\
</HTML>";
	int len = write(client_sock, reply, strlen(reply));
	if (debug)	fprintf(stdout, reply);
	if (len <= 0)
	{
		fprintf(stderr, "send reply failed reason: %s\n", strerror(errno));
	}
}

void innerError(int client_sock)
{
	const char* reply = "HTTP/1.0 500 Internal Sever Error\r\n\
Content-Type: text/html\r\n\
\r\n\
<HTML lang=\"zh-CN\">\r\n\
<meta content=\"text/html; charset=utf-8\" http-equiv=\"Content-Type\">\r\n\
<HEAD>\r\n\
<TITLE>Inner Error</TITLE>\r\n\
</HEAD>\r\n\
<BODY>\r\n\
    <P>服务器内部出错.\r\n\
</HTML>";
	int len = write(client_sock, reply, strlen(reply));
	if (debug)	fprintf(stdout, reply);
	if (len <= 0)
	{
		fprintf(stderr, "send reply failed reason: %s\n", strerror(errno));
	}
}

void badRequest(int client_sock)//400
{
	const char* reply = "HTTP/1.0 400 BAD REQUEST\r\n\
Content-Type: text/html\r\n\
\r\n\
<HTML lang=\"zh-CN\">\r\n\
<meta content=\"text/html; charset=utf-8\" http-equiv=\"Content-Type\">\r\n\
<HEAD>\r\n\
<TITLE>BAD REQUEST</TITLE>\r\n\
</HEAD>\r\n\
<BODY>\r\n\
    <P>Your browser sent a bad request！\r\n\
</BODY>\r\n\
</HTML>";
	int len = write(client_sock, reply, strlen(reply));
	if (debug)	fprintf(stdout, reply);
	if (len <= 0)
	{
		fprintf(stderr, "send reply failed reason: %s\n", strerror(errno));
	}
}